
function getval(id){ return document.getElementById(id).value; }

function getvalhtml(id){ return document.getElementById(id).innerHTML; }

function getel(id){ return document.getElementById(id); }

function getxhr() {
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } 
			catch(e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
		} else { xhr = new XMLHttpRequest(); }
	} else { alert("XMLHTTPRequest not supported..."); return null; }
	return xhr;
}


var ws_url = "./player.php"; // singleton
var xhr = null; //singleton
function callws(data, callback, target){
	returnXml = typeof returnXml !== 'undefined' ? returnXml : true;
	if (xhr && xhr.readyState != 0) {
		xhr.abort(); // cancel request
	}
	xhr = getxhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			callback(xhr.responseText, target);
		}
	}
	xhr.open("POST", ws_url,true);
	xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
	xhr.send(data);
}

function request_json(cmd, args){
	var req = JSON.stringify({cmd:cmd, args:args});
	return req
}

function readresponse_cb(data, target) {
	var rsp = JSON.parse(data);
	if (rsp.code != 200) { alert(rsp.msg); } else { if (target != null) { target.innerHTML = rsp.msg; } }
}

function readresponse_raw_cb(data, target) {	
	target.innerHTML = data;
}